cmake_minimum_required(VERSION 3.20)
project(fastHistogram LANGUAGES CXX CUDA)

# 设置C++、CUDA标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 14)

# 查找OpenCV包
find_package(OpenCV REQUIRED)
if(NOT OpenCV_FOUND)
    message(FATAL_ERROR "OpenCV not found")
endif()

# 查找CUDA包
find_package(CUDA REQUIRED)
if(NOT CUDA_FOUND)
    message(FATAL_ERROR "CUDA not found")
endif()
find_package(CUDAToolkit REQUIRED)

# 设置源文件
file(GLOB CPP_SOURCES "*.cpp")
file(GLOB CUDA_SOURCES "*.cu")

# 添加可执行文件
add_executable(${PROJECT_NAME} ${CPP_SOURCES} ${CUDA_SOURCES})

# CUDA编译选项配置
target_compile_options(${PROJECT_NAME} PRIVATE
    $<$<COMPILE_LANGUAGE:CUDA>:
    -O3 
    # -Xptxas -v 
    -lineinfo
    >
)

# 指定目标GPU架构
set_target_properties(${PROJECT_NAME} PROPERTIES
    CUDA_ARCHITECTURES "61")

# 包含目录
target_include_directories(${PROJECT_NAME} PRIVATE
    ${OpenCV_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
)

# 链接库
target_link_libraries(${PROJECT_NAME} PRIVATE
    ${OpenCV_LIBS} ${CUDA_LIBRARIES})

